#include "trie.h"
#include "getconf.h"
#define INIT_MEM_SIZE 1000000
#define IP_NUM 00000

/*!
 *@param data [O] 得到的时间字符串
 *@return 无返回值
 */
void outputtime(char *data)
{
    time_t timep;
    struct tm *p;
    time(&timep);
    p = localtime(&timep);
    strftime(data,20,"%F %X",p);
}

void random_create(unsigned int ip_num)
{
    char data[33];
    srand(time(NULL));
    unsigned int ran;
    char data1[20] ;
    outputtime(data1);
    printf("start insert time is :%s\n",data1);
    unsigned  int i =0;
    for(;i<ip_num;i++) {
        ran = (rand()*rand())%4294967296;
		ran = htonl(ran);
		const	char *ret = inet_ntop(AF_INET,&ran,data,16);
		if(NULL == ret)
			break;			
		strcat(data,"/");
		ran = rand()%29+2;
		char num[3];
		sprintf(num,"%u",ran);
		strcat(data,num);
		insert_subnet(data,1,1);
    }
    outputtime(data1);
    printf("end insert time is :%s :%u\n",data1,i);
}
void random_search(unsigned int ip_num)
{
    srand(time(NULL));
    unsigned  int ran;
    char data1[20] ;
    outputtime(data1);
    printf("start search time is :%s\n",data1);
    unsigned  int i =0;
	char subnet[20];
	unsigned int  b,w;
    for(;i<ip_num;i++) {
        ran = (rand()*rand())%4294967296;
		ran = htonl(ran);
		get_subnet(ran,subnet,&b,&w);
    }
    outputtime(data1);
    printf("end search time is :%s :%u:%u %u\n",data1,i,b,w);
}
int main()
{
    char str[50];

	int port;
	port = get_proxy_port();
		printf("proxy_dns:%d\n",port);	

	port = get_bind_port();
		printf("bind_dns:%d\n",port);	
	port = get_redis_port();
		printf("redis_dns:%d\n",port);	
	port = get_is_log();
		printf("is_log:%d\n",port);	
	get_redis_server(str);
		printf("redis_server:%s\n",str);
	get_bind_server(str) ;
		printf("bind_server:%s\n",str);
	return 0;
	if( 0 != init_trie(INIT_MEM_SIZE))
		return 1;
	
	unsigned int ip_num ;
	printf("input ip number\n ");
	scanf("%d", &ip_num);
	while(ip_num != 0)
	{
    random_create(ip_num);
	random_search(ip_num);
	
	printf("input ip number\n ");
	scanf("%d", &ip_num);
	}
 ok:printf("now is insert pattern,input search change\n");
    scanf("%s",str);
	while(strcmp(str,"search") != 0) {
        	printf("insert %s result is %d\n",str,insert_subnet(str,2,2));
			scanf("%s",str);
	}
    printf("now is search pattern,input 0 change\n");
	unsigned int  b,w, ran;
    scanf("%u",&ran);
    while(ran != 0) {
		ran = htonl(ran);
	   	char subnet[20];
		char ip[16];
		inet_ntop(AF_INET,&ran,ip,16);
		printf("ip %s\n",ip);
		if(get_subnet(ran,subnet,&b,&w) != 0) {
			printf("search failed\n");
		}
		else {
				printf("search successful,subnet is %s %u %u\n",subnet,b,w);
		}
    	scanf("%u",&ran);
    }
    printf("now is remove pattern,input quit change\n");
    scanf("%s",str);
    while(strcmp(str,"quit")!= 0) {
        printf("remove %s result is %d\n",str,remove_subnet(str));
        scanf("%s",str);
    }
    printf("shutdown process input exit,else change to search\n");
    scanf("%s",str);
    if(0 != strcmp(str,"exit"))
    goto ok;
    delete_trie();
	return 0;
}
